package middleware

import (
	"godco/internal/svc"
	"net/http"
)

type AuthMiddleware struct {
	svcCtx *svc.ServiceContext
}

func NewAuthMiddleware(svcCtx *svc.ServiceContext) *AuthMiddleware {
	return &AuthMiddleware{
		svcCtx: svcCtx,
	}
}

func (m *AuthMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		//从请求头中获取Token
		//authHeader := r.Header.Get("Authorization")
		//if authHeader == "" {
		//	httpx.Error(w, errors.New("Authorization header is missing"))
		//	return
		//}
		//
		////提取 Token
		//parts := strings.Split(authHeader, " ")
		//if len(parts) != 2 || parts[0] != "Bearer" {
		//	httpx.Error(w, errors.New("Invalid Authorization header"))
		//	return
		//}
		//
		//tokenString := parts[1]
		//// 验证 Token
		//if !utils.VerifyToken(m.svcCtx.Config.TokenVerifyConf.AK, m.svcCtx.Config.TokenVerifyConf.SK, tokenString) {
		//	httpx.Error(w, errors.New("Invalid token"))
		//	return
		//}

		// Token 验证通过，继续处理请求
		next(w, r)
	}
}
